export default {
  addToCart(context, payload){
    return new Promise(resolve => {
      // 1.查找是否如有新商品
      const oldProduct = context.state.cartList.find(item => item.iid === payload.iid)
      // 2.根据是否有新商品做出判断
      if(oldProduct){
        context.commit('addCounter',oldProduct )
        resolve('当前商品数量+1')
      }else {
        context.commit('addCart', payload)
        resolve('添加了新的商品')
      }
    })
  },
  // 给商品添加checked属性
  changeChecked(context, payload){
    for(let item of context.state.cartList){
      if(item.iid === payload.iid){
        context.commit('Checked', {item,payload})
      }
    }
  }
}